package Test;

import java.util.Random;
import java.util.Scanner;

public class test4 {
    public static void main(String[] args) {
        //生成中奖号码
        int[] arr = getNumber();
        System.out.println("=============");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        System.out.println("=============");
        //输入抽中的号码
        int[] userInput = userInputNumber();

        //判断用户中奖情况
        int redCount = 0;
        int blueCount = 0;
        //判断红球中奖情况
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                if (arr[j] == userInput[i]) {
                    redCount++;
                    break;
                }
            }
        }
        //判断篮球中奖情况
        if (arr[arr.length - 1] == userInput[userInput.length - 1]) {
            blueCount++;
        }

//        //输出中奖情况
//        System.out.println(redCount);
//        System.out.println(blueCount);

        //对应中奖结果
        if (redCount == 6 && blueCount == 1) {
            System.out.println("恭喜你中奖1000万");
        } else if (redCount == 6 && blueCount == 0) {
            System.out.println("恭喜你中奖500万");
        } else if (redCount == 5 && blueCount == 1) {
            System.out.println("恭喜你中奖3000");
        } else if ((redCount == 5 && blueCount == 0) || (redCount == 4 && blueCount == 1)) {
            System.out.println("恭喜你中奖200");
        } else if ((redCount == 4 && blueCount == 0) || (redCount == 3 && blueCount == 1)) {
            System.out.println("恭喜你中奖10");
        } else if ((redCount == 2 && blueCount == 1) || (redCount == 1 && blueCount == 1) || (redCount == 0 && blueCount == 1)) {
            System.out.println("恭喜你中奖5");
        } else {
            System.out.println("谢谢参与");
        }

    }

    //获取随机的6个红球和一个篮球
    public static int[] getNumber() {
        //添加红球号码  随机选1-33的数到数组
        int[] arr = new int[7];
        Random r = new Random();
        for (int i = 0; i < 6; ) {
            int num = r.nextInt(33) + 1;
            boolean flag = contains(arr, num);
            if (!flag) {
                arr[i] = num;
                i++;
            }
        }
        //添加篮球号码
        arr[arr.length - 1] = r.nextInt(16) + 1;
        return arr;
    }

    //用户输入号码
    public static int[] userInputNumber() {
        int[] arr = new int[7];
        Scanner sc = new Scanner(System.in);
        //输入红球号码
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第" + (i + 1) + "个红球号：");
            int redNumber = sc.nextInt();
            if (redNumber <= 33 && redNumber >= 1) {
                boolean flag = contains(arr, redNumber);
                if (!flag) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("当前红号码已存在，请重新输入");
                }
            } else {
                System.out.println("当前号码超出范围");
            }
        }
        //输入篮球号码
        while (true) {
            System.out.println("请输入蓝色号码：");
            int blueNumber = sc.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            } else {
                System.out.println("当前号码超出范围");
            }
        }
        return arr;
    }

    public static boolean contains(int[] arr, int num) {
        for (int i = 0; i < 6; i++) {
            if (arr[i] == num) {
                return true;
            }
        }
        return false;
    }
}
